<?php

//栏目分类设置
if (POWER != 5) {
  err('该命令必须以基本管理员身份登陆！请重登陆');
}
//过滤主题
function filter1($text) {
  $text = trim($text);
  $text = stripslashes($text);
  //$text = htmlspecialchars($text);
  $text = str_replace('"', '&quot;', $text);
  $text = str_replace('\'', '&#039;', $text);
  $text = str_replace('<', '&lt;', $text);
  $text = str_replace('>', '&gt;', $text);
  $text = preg_replace('/[\s\r\n]+|&nbsp;|　/i', '', $text);
  return $text;
}
if ($_POST['act'] == 'img') {
  require ('writable/extra/inc/set/img.php');
  $extra['name'] = '新闻图片';
  $url = filter1($_POST['extra_url']);
  if ($url == '') {
    err('采集源url不能空！');
  } else {
    $extra['url'] = $url;
  }
  if (!$_POST['extra_w'] || !is_numeric($_POST['extra_w']) || $_POST['extra_w'] <= 0) {
    err('采集图片生成宽度必须大于0！');
  } else {
    $extra['w'] = $_POST['extra_w'];
  }
  if (!isset($_POST['p_time']) || !is_numeric($_POST['p_time']) || (string)$_POST['p_time'] == '') {
    $extra['time_step'] = '';
  } else {
    if ($_POST['p_time'] == 1) {
      if (!abs($_POST['p_time_val']) > 0) {
        err('采集时效若以分钟为间隔必须大于0啊！');
      } else {
        $extra['time_step'] = abs($_POST['p_time_val']);
      }
    } else {
      $_POST['p_time_key'] = abs($_POST['p_time_key']);
      $extra['time_step'] = $_POST['p_time_key'] > 0 ? '-'.$_POST['p_time_key'] : 0;
    }
  }
  $extra['img_d'] = 'img/img';
  $text = '<?php
$extra = '.var_export($extra, true).';
?>';

  @ require ('readonly/function/write_file.php');
  write_file('writable/extra/inc/code/img_php.php', $_POST['extra_code_php']);
  write_file('writable/extra/inc/code/img_css-js.php', $_POST['extra_code_css-js']);
  write_file('writable/extra/inc/set/img.php', $text);
  alert('设置成功！', '?get=extra#po0');


} elseif ($_POST['act'] == 'li') {
  require ('writable/extra/inc/set/li.php');
  $extra['name'] = '新闻摘要';
  $url = filter1($_POST['extra_url']);
  if ($url == '') {
    err('采集源url不能空！');
  } else {
    $extra['url'] = $url;
  }
  if (!empty($_POST['extra_hot']) && !preg_match('/^[\-\w]+$/', $_POST['extra_hot'])) {
    err('预显示标签 只能为字母、数字、中划线和下划线');
  } else {
    $extra['hot'] = $_POST['extra_hot'];
  }
  if (!isset($_POST['p_time']) || !is_numeric($_POST['p_time']) || (string)$_POST['p_time'] == '') {
    $extra['time_step'] = '';
  } else {
    if ($_POST['p_time'] == 1) {
      if (!abs($_POST['p_time_val']) > 0) {
        err('采集时效若以分钟为间隔必须大于0啊！');
      } else {
        $extra['time_step'] = abs($_POST['p_time_val']);
      }
    } else {
      $_POST['p_time_key'] = abs($_POST['p_time_key']);
      $extra['time_step'] = $_POST['p_time_key'] > 0 ? '-'.$_POST['p_time_key'] : 0;
    }
  }
  $extra['img_d'] = 'img/li';
  $text = '<?php
$extra = '.var_export($extra, true).';
?>';

  @ require ('readonly/function/write_file.php');
  write_file('writable/extra/inc/code/li_php.php', $_POST['extra_code_php']);
  write_file('writable/extra/inc/code/li_css-js.php', $_POST['extra_code_css-js']);
  write_file('writable/extra/inc/set/li.php', $text);
  alert('设置成功！', '?get=extra#po1');


} elseif ($_POST['act'] == 'more') {
  require ('writable/extra/inc/set/more.php');
  $extra['name'] = '新闻集锦';
  $url = filter1($_POST['extra_url']);
  if ($url == '') {
    err('采集源url不能空！');
  } else {
    $extra['url'] = $url;
  }
  if (!isset($_POST['p_time']) || !is_numeric($_POST['p_time']) || (string)$_POST['p_time'] == '') {
    $extra['time_step'] = '';
  } else {
    if ($_POST['p_time'] == 1) {
      if (!abs($_POST['p_time_val']) > 0) {
        err('采集时效若以分钟为间隔必须大于0啊！');
      } else {
        $extra['time_step'] = abs($_POST['p_time_val']);
      }
    } else {
      $_POST['p_time_key'] = abs($_POST['p_time_key']);
      $extra['time_step'] = $_POST['p_time_key'] > 0 ? '-'.$_POST['p_time_key'] : 0;
    }
  }
  $extra['img_d'] = 'img/more/unfixed';
  $text = '<?php
$extra = '.var_export($extra, true).';
?>';

  @ require ('readonly/function/write_file.php');
  write_file('writable/extra/inc/code/more_php.php', $_POST['extra_code_php']);
  write_file('writable/extra/inc/code/more_css-js.php', $_POST['extra_code_css-js']);
  write_file('writable/extra/inc/set/more.php', $text);
  alert('设置成功！', '?get=extra#po123');


} elseif ($_POST['act'] == '360side') {
  @ require ('readonly/function/write_file.php');
  write_file('writable/extra/inc/code/360side_css-js.php', $_POST['extra_code_css-js']);
  alert('设置成功！', '?get=extra#360side');


} elseif ($_POST['act'] == '360bottom') {
  @ require ('readonly/function/write_file.php');
  write_file('writable/extra/inc/code/360bottom_css-js.php', $_POST['extra_code_css-js']);
  alert('设置成功！', '?get=extra#360bottom');


} elseif ($_POST['act'] == 'chongzhi') {
  $_POST['chongzhi'] = filter1($_POST['chongzhi']);
  $_POST['mobile'] = filter1($_POST['mobile']);
  $_POST['price'] = filter1($_POST['price']);
  if (!$_POST['chongzhi']) {
    err('手机充值 URL不能空！');
  }
  if (!$_POST['mobile']) {
    err('表单文本域「手机号码」标签名不能空！');
  }
  if (!$_POST['price']) {
    err('表单文本域「充值金额」标签名不能空！');
  }
  @ require ('readonly/function/write_file.php');
  write_file('writable/require/chongzhi.txt', ''.(isset($_POST['chongzhi_open']) && $_POST['chongzhi_open']==1?1:0).'
'.(isset($_POST['chongzhi_for']) && $_POST['chongzhi_for']==1?1:0).'
'.$_POST['mobile'].'
'.$_POST['price'].'
'.$_POST['chongzhi'].'');
  if (!isset($web['html'])) {
	@ require ('writable/set/set_html.php');
  }
  if ($web['html'] == true) {
    if (filesize('index.php') == filesize('index_menhu.php')) {
      reset_indexhtml('index.php', 'index.html');
    }
  }
  alert('设置成功！', '?get=extra#po2');

} elseif ($_POST['act'] == 'newsite') {
  if ($_POST['newsite'] == 1) {
    if (!copy('readonly/require/newsite.php', 'writable/require/newsite.php')) {
      err('开启新录网站失败！原因：writable/require/目录无写权限');
    }
  } else {
    @ unlink('writable/require/newsite.php');
  }
  @ require ('readonly/function/write_file.php');
  @ require ('writable/set/set_html.php');
  reset_indexhtml('index.php', 'index.html');
  alert('设置成功！', '?get=extra#po3');

} elseif ($_POST['act'] == 'newinfo') {
  if ($_POST['newinfo'] == 1) {
    if (!copy('readonly/require/newinfo.php', 'writable/require/newinfo.php')) {
      err('开启信息窗失败！原因：writable/require/目录无写权限');
    }
  } else {
    @ unlink('writable/require/newinfo.php');
  }
  if (!$text = @file_get_contents('writable/set/set.php')) {
    err('无法读取设置文件！稍候再试！');
  }
  $text = preg_replace('/\$web\[(\'|\")newinfo_url(\'|\")\][^\;]+/', '$web[\'newinfo_url\'] = '.(empty($_POST['newinfo_url'][0]) || empty($_POST['newinfo_url'][1])?'array("http://info.162100.com/get_newinfo_for162100.php", "http://info.162100.com/write.php")':'array("'.filter1(preg_replace('/\/+$/', '', $_POST['newinfo_url'][0])).'","'.filter1(preg_replace('/\/+$/', '', $_POST['newinfo_url'][1])).'")').'', $text);
  @ require ('readonly/function/write_file.php');
  write_file('writable/set/set.php', $text);
  @ require ('writable/set/set_html.php');
  reset_indexhtml('index.php', 'index.html');
  alert('设置成功！', '?get=extra#po3');

} else {
  err('参数错误！');
}


?>